package com.ycx.furns.dao.impl;

import com.ycx.furns.dao.BasicDAO;
import com.ycx.furns.dao.MemberDAO;
import com.ycx.furns.entity.Member;

public class MemberDAOImpl extends BasicDAO<Member> implements MemberDAO {
    @Override
    public Member getMember(String name) {
        String sql = "SELECT * FROM member WHERE username=?";
        return querySingle(sql, Member.class, name);
    }

    @Override
    public int saveMember(Member member) {
        String name = member.getUsername();
        String password = member.getPassword();
        String email = member.getEmail();

        String sql = "INSERT INTO member(username,`password`,`email`) VALUES(?,md5(?) ,?)";
        return update(sql, name, password, email);
    }

    @Override
    public Member getMemberByNameAndPwd(String name, String pwd) {
        String sql = "SELECT * FROM member WHERE username=? AND `password` = md5(?)";
        return querySingle(sql, Member.class, name, pwd);
    }
}
